home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / jdp1_4.zip / JDP1_4.EXE / data.1 / JDPLayout4.java < prev    next >
Text File  |  1996-10-18  |  12KB  |  393 lines

  1. >XXX0384  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13. import java.util.Date;
  14.  
  15.  
  16. >003public class <JDPUserBill> extends JDPClassLayout {
  17.  
  18.     JDPUser user;
  19.     JDPJagg jaggSQL;
  20.     JDPTextGrid tableContents;
  21.     JDPWhereClause jdpWhereClause;
  22.  
  23.     String[] psortChoice;
  24.     String[] pdisplayChoice;
  25.     int itemIndex;
  26.     boolean insertRequested = false;
  27.     boolean deleteRequested = false;
  28.     String pfromWhereClause;
  29.     String[][] rowKey;
  30.     int keyCount;
  31.     int prevColumnCount;
  32. >119    int columnCount = <columnCount>;
  33.  
  34.     Vector pmatchUsing;
  35.     Vector pactualmatchUsing;
  36.  
  37.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  38.  
  39.         this.user = user;
  40.         //
  41.         //  Set JAGG settings for this class
  42.         //
  43.         jaggSQL = new JDPJagg(user.jaggPath);
  44.         jaggSQL.setNULL("space");
  45. >995        jaggSQL.setMRW("<maxRows>");
  46. >998        jaggSQL.setDSN("<datasource>");
  47. >999        jaggSQL.setCSTR("<connectstr>");
  48.  
  49.         setLayout(new BorderLayout());
  50.         setFont(user.plainFont);
  51.  
  52.         Panel mainPanel = new Panel();
  53.         mainPanel.setLayout(new BorderLayout());
  54.         Panel centerMainPanel = new Panel();
  55.         centerMainPanel.setLayout(new BorderLayout());
  56.  
  57.         //
  58.         //  Create a new instance of a Grid
  59.         //
  60.         tableContents = new JDPTextGrid(user);
  61.         mainPanel.add("Center",tableContents);
  62.         centerMainPanel.add("Center",mainPanel);
  63.         
  64.         //
  65.         //  Define parameters for JDPWhereClause
  66.         //
  67. >016        String[] pchooseFrom = new String[<7>];
  68. >017        pchooseFrom[<0>] = "<Account Name>";
  69.  
  70. >018        String[] pactualchooseFrom = new String[<7>];
  71. >019        pactualchooseFrom[<0>] = "<username>";
  72.  
  73.         loadMatchUsing();
  74.  
  75. >024        boolean[] constantIsString = new boolean[<7>];
  76. >025        constantIsString[<0>] = <true>;
  77.  
  78. >026        int[] constantLength = new int[<7>];
  79. >027        constantLength[<0>] = <20>;
  80.  
  81.         //
  82.         //  Add JDPWhereClause search panel
  83.         //
  84.         if (pchooseFrom.length > 0) {
  85. >028            jdpWhereClause = new JDPWhereClause(user, targetPanel, "<UserBill>", false, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  86.                                                 pmatchUsing, pactualmatchUsing, null, null,
  87.                                                 constantLength, constantIsString);
  88.             centerMainPanel.add("North",jdpWhereClause);
  89.         }
  90.  
  91. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",centerMainPanel,"North"));
  92.         loadGrid();
  93.  
  94.         //
  95.         //  Add the handle to this panel to the global vector so other panels can
  96.         //  access this one
  97.         //
  98.         user.gParm.addElement(this);
  99.     }
  100.  
  101.     //
  102.     //  Handle screen events
  103.     //
  104.     public boolean handleEvent(Event e) {
  105.  
  106.         switch (e.id) {
  107.         case Event.ACTION_EVENT:
  108.             if (e.target instanceof Button) {
  109.                 String choice = (String)e.arg;
  110.                 if (choice.trim().compareTo("Search") == 0) {
  111.                     newSearch();
  112.                     return true;
  113.                 }
  114.                 return false;
  115.             }
  116.             if (e.target instanceof Choice) {
  117.                 return true;
  118.             }
  119.             if (e.target instanceof TextField) {
  120.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  121.                     newSearch();
  122.                     return true;
  123.                 }
  124.                 return true;
  125.             }
  126.             return false;
  127.  
  128.         case Event.WINDOW_EXPOSE:
  129.             if (e.target instanceof JDPTabSelectPanel) {
  130.                 //
  131.                 //  This is where you place code to get executed when this panel is
  132.                 //  reactivated from the tab menu
  133.                 //
  134.                 return true;
  135.             }
  136.             return false;
  137.  
  138.         default:
  139.             return false;
  140.  
  141.         }
  142.     }
  143.  
  144.     //
  145.     //  Retrieve the handle to another panel so as to be able to interact with it
  146.     //
  147.     public void retrieveHandle() {
  148.  
  149.         for (int ix=0; ix<user.gParm.size(); ix++) {
  150.             //
  151.             //  Activate the next four lines of code to retrieve the handle to another 
  152.             //  Panel within your JDP system. Of course you should declare the variable 
  153.             //  at the top of this source instead of within this method so you can 
  154.             //  access it from all the methods within this class. You only need to 
  155.             //  substitute DemoClass with the name ouf your class. You should call this 
  156.             //  method from somewhere else in this class. To access a variable from 
  157.             //  your resulting class use:
  158.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  159.             //
  160. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  161. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  162. //                return;
  163. //            }
  164.         }
  165.     }
  166.  
  167.     //
  168.     //  The search button was pressed so rerun the query with the new search criteria
  169.     //
  170.     public void newSearch() {
  171.  
  172.         loadGrid();
  173.     }
  174.  
  175.     //
  176.     //  Load the grid with the specified parameters and selected data
  177.     //
  178.     public void loadGrid() {
  179.  
  180.         StringTokenizer stok;
  181.         int recCount = 0;
  182.         Vector results = new Vector();
  183.         String sep = jaggSQL.getSEP();
  184.         int actualRows = 0;
  185.         String row;
  186.         float[][] worksubTotal;
  187.         float[][] workgrandTotal;
  188.  
  189.         Vector columns = new Vector();
  190.         Vector indexes = new Vector();
  191.  
  192. >100        String SQL = <SELECT>;
  193.  
  194.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  195.  
  196.         recCount = jaggSQL.execSQL(SQL, results);
  197.  
  198.         if(recCount == -1) {
  199.             user.u.setSqlMessage(jaggSQL,SQL);
  200.             return;
  201.         }
  202.  
  203.         //
  204.         //  Initialise result arrays
  205.         //
  206.         actualRows = jaggSQL.getRowCount();
  207.         tableContents.currentText = new String[columnCount][actualRows+30];
  208.         tableContents.cellFont = new Font[columnCount][actualRows+30];
  209.         tableContents.gridColor = Color.white;
  210.         boolean[] totalThisColumn = new boolean[columnCount];
  211.         //
  212.         //  If we haven't already initialise the grid settings
  213.         //
  214.         if (columnCount != prevColumnCount) {
  215.             prevColumnCount = columnCount;
  216.             setGridSettings();
  217.         }
  218.         String[] lastItem = new String[columnCount];
  219. >125        boolean[] subTotal = new boolean[<>];
  220. >125        boolean[] grandTotal = new boolean[<>];
  221. >126        int orderBy = <>;
  222. >127        subTotal[<>] = <>;
  223. >128        grandTotal[<>] = <>;
  224. >129        totalThisColumn[<>] = <>;
  225.         //
  226.         //  Load arrays and result List
  227.         //
  228.         worksubTotal = new float[1][1];
  229.         workgrandTotal = new float[1][1];
  230.         int xOffset = 0;
  231.         int    xIncrement = 0;
  232.         int titlePos = (int)(columnCount/2)-1;
  233.         if (titlePos < 0) titlePos = 0;
  234. >124        tableContents.currentText[titlePos][1] = "<>";
  235.         tableContents.cellFont[titlePos][1] = new Font(user.plainFont.getName(),Font.BOLD,user.plainFont.getSize()+4);
  236.         for (int iy=0; iy<columnCount; iy++) {
  237.             tableContents.cellFont[iy][3] = user.boldFont;
  238.         }
  239. >101        tableContents.currentText[<ix>][3] = "<>";
  240.         xOffset = 4;
  241.         worksubTotal = new float[orderBy][columnCount];
  242.         workgrandTotal = new float[orderBy][columnCount];
  243.         int ix;
  244.         for (ix=0; ix<actualRows; ix++) {
  245.             row = (String)results.elementAt(ix);
  246.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  247.                 stok = new StringTokenizer(row);
  248.                 for (int iy=0; iy<columnCount; iy++) {
  249.                     tableContents.currentText[iy][ix+xOffset] = stok.nextToken(sep).trim();
  250.                 }
  251.                 for (int iy=columnCount-1; iy>=0; iy--) {
  252.                     String thisItem = tableContents.currentText[iy][ix+xOffset];
  253.                     if ((orderBy > iy) && (ix > 0)) {
  254.                         if (thisItem.equals(lastItem[iy])) {
  255.                             tableContents.currentText[iy][ix+xOffset] = "";
  256.                         } else {
  257.                             if (subTotal[iy]) {
  258.                                 for (int iz=0; iz<columnCount; iz++) {
  259.                                     tableContents.currentText[iz][ix+xOffset+1] = tableContents.currentText[iz][ix+xOffset];
  260.                                     tableContents.currentText[iz][ix+xOffset] = "";
  261.                                     tableContents.cellFont[iz][ix+xOffset+1] = tableContents.cellFont[iz][ix+xOffset];
  262.                                     tableContents.cellFont[iz][ix+xOffset] = null;
  263.                                 }
  264.                                 tableContents.currentText[iy][ix+xOffset] = "Subtotal";
  265.                                 tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  266.                                 for (int iw=iy+1; iw<columnCount; iw++) {
  267.                                     if (totalThisColumn[iw]) {
  268.                                         tableContents.currentText[iw][ix+xOffset] = user.u.str(worksubTotal[iy][iw],11,3).trim();
  269.                                         tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  270.                                     }
  271.                                     worksubTotal[iy][iw] = 0;
  272.                                 }
  273.                                 xOffset += 1;
  274.                             }
  275.                             tableContents.currentText[iy][ix+xOffset] = thisItem;
  276.                         }
  277.                     }
  278.                     if ((orderBy > 0) && (ix > 0)) {
  279.                         try {
  280.                             float tempfloat = Float.valueOf(lastItem[iy]).floatValue();
  281.                             for (int iz=0; iz<orderBy; iz++) {
  282.                                 worksubTotal[iz][iy] += tempfloat;
  283.                                 workgrandTotal[iz][iy] += tempfloat;
  284.                             }
  285.                         } catch(Exception e) { 
  286.                         }
  287.                     }
  288.                     lastItem[iy] = thisItem;
  289.                 }
  290.             }
  291.         }
  292.  
  293.         for (int iy=0; iy<columnCount; iy++) {
  294.             try {
  295.                 float tempfloat = Float.valueOf(lastItem[iy]).floatValue();
  296.                 for (int iz=0; iz<orderBy; iz++) {
  297.                     worksubTotal[iz][iy] += tempfloat;
  298.                     workgrandTotal[iz][iy] += tempfloat;
  299.                 }
  300.             } catch(Exception e) { 
  301.             }
  302.         }
  303.         for (int iy=columnCount-1; iy>=0; iy--) {
  304.             if (orderBy > iy) {
  305.                 if (subTotal[iy]) {
  306.                     tableContents.currentText[iy][ix+xOffset] = "Subtotal";
  307.                     tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  308.                     for (int iw=iy+1; iw<columnCount; iw++) {
  309.                         if (totalThisColumn[iw]) {
  310.                             tableContents.currentText[iw][ix+xOffset] = user.u.str(worksubTotal[iy][iw],11,3).trim();
  311.                             tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  312.                         }
  313.                     }
  314.                     xOffset += 1;
  315.                 }
  316.             }
  317.         }
  318.         for (int iy=columnCount-1; iy>=0; iy--) {
  319.             if (orderBy > iy) {
  320.                 if (grandTotal[iy]) {
  321.                     tableContents.currentText[iy][ix+xOffset] = "Total";
  322.                     tableContents.cellFont[iy][ix+xOffset] = user.boldFont;
  323.                     for (int iw=iy+1; iw<columnCount; iw++) {
  324.                         if (totalThisColumn[iw]) {
  325.                             tableContents.currentText[iw][ix+xOffset] = user.u.str(workgrandTotal[iy][iw],11,3).trim();
  326.                             tableContents.cellFont[iw][ix+xOffset] = user.boldFont;
  327.                         }
  328.                     }
  329.                     xOffset++;
  330.                 }
  331.             }
  332.         }
  333.  
  334.         tableContents.newTable();
  335.  
  336.         //
  337.         //  Clear status message
  338.         //
  339.         user.mainmsg.clearStatusMsg();
  340.     }
  341.  
  342.     //
  343.     //  Set up the parameters for this grid
  344.     //
  345.     public void setGridSettings() {
  346.  
  347.         tableContents.columnHeader = null;
  348.         tableContents.columnHeaderStyle = new int[columnCount];
  349.         tableContents.columnStyle = new int[columnCount];
  350.         tableContents.columnHeaderColor = new Color[columnCount];
  351.         tableContents.columnColor = new Color[columnCount];
  352.         tableContents.columnBGColor = new Color[columnCount];
  353.         tableContents.columnProtected = new boolean[columnCount];
  354.         tableContents.columnWidth = new int[columnCount];
  355.         tableContents.rightJustify = new boolean[columnCount];
  356.         tableContents.rowHeader = null;
  357.         tableContents.columnHeight = null;
  358.         for (int ix=0; ix<columnCount; ix++) {
  359.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  360.             tableContents.columnStyle[ix] = Font.PLAIN;
  361.             tableContents.columnHeaderColor[ix] = Color.black;
  362.             tableContents.columnColor[ix] = Color.black;
  363.             tableContents.columnBGColor[ix] = Color.white;
  364.             tableContents.columnStyle[ix] = Font.PLAIN;
  365.         }
  366. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  367. >103        tableContents.columnStyle[<ix>] = <>;
  368. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  369. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  370. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  371. >107        tableContents.columnProtected[<ix>] = <>;
  372. >108        tableContents.columnWidth[<ix>] = <>;
  373. >109        tableContents.rightJustify[<ix>] = <>;
  374.  
  375.     }
  376.  
  377.     //
  378.     //  Load the Search Layout pulldown choices
  379.     //
  380.     public void loadMatchUsing() {
  381.  
  382.         pmatchUsing = new Vector();
  383.         pactualmatchUsing = new Vector();
  384. >020        pmatchUsing.addElement(new Vector());
  385. >022        pactualmatchUsing.addElement(new Vector());
  386. >021        ((Vector)pmatchUsing.elementAt(<0>)).addElement("<Begins with>");
  387. >023        ((Vector)pactualmatchUsing.elementAt(<0>)).addElement("< like >");
  388.  
  389.     }
  390.  
  391.  
  392. }
  393.